<?php
/**
 * Mechanism
 * 
 * LICENSE
 * 
 * This file is private intellectual property of the author. 
 * All rights reserved. Copying and illegal using is punishable by law.
 * 
 * @copyright Copyright (c) 2011 BreatheInMyVoid ( BreatheInMyVoid@gmail.com )
 */

namespace Mechanism\Controller {
	use Mechanism\Request,
		Mechanism\Response,
		Mechanism\Director,
		Mechanism\Router,
		Mechanism\Router\Route;
	/**
 	 * 
 	 */
 	class Front implements IFront {
 		protected $request = null;
 		protected $routes = null;
		protected $router = null;
		protected $director = null;
		protected $response = null;
		protected $app_path = null;

		public function get_request( ) {
			return $this->request;
		}
		
		public function get_routes( ) {
			return $this->routes;
		}
		
		public function get_router( ) {
			return $this->router;
		}
		
		public function get_director( ) {
			return $this->director;
		}
		
		public function get_response( ) {
			return $this->response;
		}
		
		public function get_app_path( ) {
			return $this->app_path;
		}		
		
		public function set_request( Request\IRequest  $request ) {
			$this->request = $request;
			return $this;
		}
		
		public function set_routes( $routes ) {
			$this->routes = $routes;
			return $this;
		}
		
		public function set_router( Router\IRouter $router ) {
			$this->router = $router;
			return $this;
		}
		
		public function set_director( Director\IDirector $director ) {
			$this->director = $director;
			return $this;
		}	
			
		public function set_response( Response\IResponse $response ) {
			$this->response = $response;
			return $this;
		}
		
		public function set_app_path( $path ) {
			$this->app_path = $path;
			return $this;
		}

		public function run( ) {
			/* Configurate front */
			if ( null === $this->app_path ) {
				// Exception
			}
			
			if ( null === $this->request ) {
				// Exc
			}
			
			if ( null === $this->routes ) {
				/* Create standart route */
				$this->routes = array( 
					new Route\Dynamic( ':module/:controller/:action/*' ) 
				);					
			} 
			
			if ( null === $this->router ) {
				/* Create standart router */
				$this->router = new Router\Standart( $this->routes );
			} 
			
			if ( null === $this->director ) {
				/* Create standart director */
				$this->director = new Director\Standart( $this->router );
			}
			
			/* Direct */
			$this->director->set_app_path( $this->app_path );
			$this->response = $this->director->direct( $this->request );
			return $this->response; 
		}	
	}
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
